package com.ucomm.talent.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ucomm.talent.R;
import com.ucomm.talent.activity.ICustomSpinnerClickListener;


/**
 * Created with IntelliJ IDEA.
 * User: Vita Hao
 * Date: 13-5-25
 * Time: 上午11:49
 * To change this template use File | Settings | File Templates.
 */
public class SearchSpinnerView extends LinearLayout implements View.OnClickListener {
    private View layout;
    private Context mContext;
    private ICustomSpinnerClickListener spinnerClickListener;
    private TextView tv_search_context;
    private TextView tv_label;
    private int viewId;
    public void setCustomSpinnerClickListener(int viewId, ICustomSpinnerClickListener spinnerClickListener) {
        this.spinnerClickListener = spinnerClickListener;
        this.viewId = viewId;
    }

    public SearchSpinnerView(Context context) {
        super(context);
        initView(context);
    }

    public SearchSpinnerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context, attrs);
    }

    public void initView(Context context) {
        initView(context, null);
    }

    private void initView(Context context, AttributeSet attrs) {
        this.mContext = context;
        layout = LayoutInflater.from(mContext).inflate(R.layout.search_spinner_layout, null);

        tv_label = (TextView) layout.findViewById(R.id.tv_label);
        tv_search_context = (TextView) layout.findViewById(R.id.tv_search_context);
        if (attrs != null) {
            TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.searchSpinnerView);
            String text = a.getString(R.styleable.searchSpinnerView_labelTitle);
            tv_label.setText(text);
        }
        tv_search_context.setOnClickListener(this);

        this.addView(layout);
    }

    public void setDefaultSpinnerText(String value){
        this.tv_search_context.setText(value);
    }

    @Override
    public void onClick(View view) {
        if (spinnerClickListener != null)
            spinnerClickListener.onArrowClick(viewId,view);
    }
}
